library FlutterAppbar;
import 'package:flutter/material.dart';


/*
 * @class FlutterAppbar
 * @author: ZhongWb
 * @date: 2019/12/17 14:59
 * @description AppBar重写官方  自定义导航
 **/
class FlutterAppbar extends StatefulWidget  implements PreferredSizeWidget {
  final double contentHeight; //从外部指定高度
  final Color statusBarColor; //设置statusbar的颜色
  final Widget rightWidget;//右边组件
  final Widget leftWidget;//左边组件
  final double leftPadding;//左边距
  final double rightPadding;//右边距
  final String title;//标题
  final String titleWidget;//标题
  final Color titleColor;//标题颜色
  final double titleSize;//标题大小
  final Function onTapLeft;
  final BuildContext context;
  FlutterAppbar({this.title:"标题",this.titleColor:Colors.white,this.titleSize :17,this.contentHeight : 43,this.statusBarColor,this.rightWidget,this.leftWidget,this.leftPadding:3,this.rightPadding:12, this.context, this.titleWidget, this.onTapLeft});
  @override
  _AppBarCustomState createState() => _AppBarCustomState();

  @override
  Size get preferredSize => new Size.fromHeight(contentHeight);
}

class _AppBarCustomState extends State<FlutterAppbar> {
  @override
  Widget build(BuildContext context) {
    return Container(
      color: widget.statusBarColor ?? Color(0xff3D7ADD),
      child: SafeArea(
        top: true,
        child: Container(
          height: widget.contentHeight,
          child: Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: <Widget>[
              Container(
                padding: EdgeInsets.only(left: widget.leftPadding),
                height: widget.contentHeight,
                width: 100,
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.start,
                  children: widget.leftWidget ?? [
                    InkWell(
                      child: Icon(Icons.chevron_left,color: Colors.white,),
                      onTap: (){
                        if(widget.onTapLeft != null){
                          widget.onTapLeft();
                        }else{
                          Navigator.of(widget.context).pop();
                        }
                      },
                    )
                  ],
                ),
              ),
              Expanded(child: Center(child: widget.titleWidget ?? Text(widget.title,style: TextStyle(fontSize: widget.titleSize,color: widget.titleColor),overflow: TextOverflow.ellipsis,),)),
              Container(
                padding: EdgeInsets.only(right: widget.rightPadding),
                height: widget.contentHeight,
                width: 100,
                child: widget.rightWidget,
              ),
            ],
          ),
        ),
      ),
    );
  }
}
